//-----------------------------------------------------------------------------
// Name: tut2main.cpp
// Auth: Bradford J. Smith & Robert Darty
// Desc: This tutorial code demonstrates the basics of 2D in openGL and also
//	uses the Corona library to load and display an image.
//-----------------------------------------------------------------------------

#include "Assert.h"
#include "Display.h"
#include "DisplayManager.h"
#include "Input.h"
#include "RobTown.h"
#include "Systems.h"
#include "InputManager.h"
#include "corona/corona.h"

#include <gl/glut.h>
#include <gl/freeglut_ext.h>


//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
corona::Image* gpWheelImageData;

//-----------------------------------------------------------------------------
// Function Prototypes:
//-----------------------------------------------------------------------------
void Initialize();
void InitObjects();
void ShutdownObjects();
void InitDisplay();
void ShutdownDisplay();


//-----------------------------------------------------------------------------
// Desc: The main function of this programs serves to setup OpenGL, initialize
//			the program, set up all the callback functions, and start the 
//			event loop.
int main(int argc, char* argv[])
{
	// Initialize OpenGL
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(kInitialWindowWidth, kInitialWindowHeight);
	glutInitWindowPosition(0, 0);

	glutCreateWindow("Braaaaaiiiiiins!!!!!");

// Call the program specific initialization
	Initialize();

	// Set up all of the callback functions.
	glutReshapeFunc(ReshapeFunction);
	glutKeyboardFunc(KeyDownFunction);
	glutKeyboardUpFunc(KeyUpFunction);
	glutDisplayFunc(DisplayFunction);
	glutSpecialFunc(SpecialKeyDownFunction);
	glutSpecialUpFunc(SpecialKeyUpFunction);
	glutIdleFunc(DisplayFunction);
	glutPassiveMotionFunc(MouseMoveFunction);
	glutMotionFunc(MouseMoveFunction);
	glutMouseFunc(MouseClickFunc);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	glutWarpPointer(kInitialWindowWidth/2, kInitialWindowHeight/2);
	InitSystems();
	InitDisplay();
	InitObjects();

	// Start the event processing loop.
	glutMainLoop();

	ShutdownDisplay();
	ShutdownObjects();
	ShutdownSystems();

	return 0;
}

void InitObjects()
{

}

void ShutdownObjects()
{
	// Doesn't need to do anything right now.
}

//-----------------------------------------------------------------------------
// Desc: Creates all image data needed for the display
void InitDisplay()
{

}

//-----------------------------------------------------------------------------
// Desc: Cleans up any display related state and variables when the application
//		shuts down
void ShutdownDisplay()
{

}

//-----------------------------------------------------------------------------
// Desc: This function carries out any program specific initialization as well
//			as any OpenGL state initialization
void Initialize()
{
	glClearColor(0.95f, 0.95f, 0.95f, 0.0);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// enable depth buffering (so objects get drawn based on depth instead
	// of the raw draw order)
	glEnable(GL_DEPTH_TEST);

	// cull back faces
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	

}